<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>我的学习网</title>
    <link href="//cdn.staticfile.net/layui/2.9.14/css/layui.css" rel="stylesheet">
    <script src="/static/djs/jquery/jquery-1.8.2.min.js"></script>
    <link href="/static/djs/jcountdown/jcountdown.css" rel="stylesheet" type="text/css">
    <script src="/static/djs/jcountdown/jquery.jcountdown.min.js"></script>
</head>
<body style="background-color: #cccccc;position: fixed;width: 100%;z-index: 999;">
<!--头部开始。-->
<div style="background-color: #008800">

    <div class="layui-fluid">
        <div class="layui-row">
            <div class="layui-col-md12">
                <ul class="layui-nav layui-bg-gray">
                    <li class="layui-nav-item {block name='index'}{/block}"><a href="{:url('index/index')}"><i
                            class="layui-icon layui-icon-home"></i>&nbsp&nbsp 首页</a></li>
                    <!--                <li class="layui-nav-item layui-this"><a href="{:url('index/index')}"><i class="layui-icon layui-icon-home"></i>&nbsp&nbsp 首页</a></li>-->
                    <li class="layui-nav-item {block name='talk'}{/block}"><a href="{:url('talk/talk')}"><i
                            class="layui-icon layui-icon-template-1"></i>&nbsp&nbsp 交流社区</a></li>
                    <li class="layui-nav-item"><a href=""><i class="layui-icon layui-icon-tabs"></i>&nbsp&nbsp关于我们</a>
                    </li>

                    <!--                <li class="layui-nav-item" style="position: absolute;right: 10px;">-->
                    <!--                    <a href="javascript:;" ><img src="https://unpkg.com/outeres@0.0.10/demo/avatar/1.jpg" class="layui-nav-img">更多</a>-->
                    <!--                    <dl class="layui-nav-child">-->
                    <!--                        <dd><a href="">选项1</a></dd>-->
                    <!--                        <dd><a href="">选项2</a></dd>-->
                    <!--                        <dd><a href="">选项3</a></dd>-->
                    <!--                    </dl>-->
                    <!--                </li>-->

                    <li class="layui-nav-item" lay-unselect style="position: absolute;right: 10px;">
                        {if $Think.session.username}
                        <a href="javascript:;">
                            <img src="https://unpkg.com/outeres@0.0.10/demo/avatar/1.jpg" class="layui-nav-img">
                        </a>
                        <dl class="layui-nav-child">
                            <dd><a href="javascript:;">子级菜单</a></dd>
                            <dd><a href="javascript:;">横线隔断</a></dd>
                            <hr>
                            <dd style="text-align: center;"><a href="">退出</a></dd>
                        </dl>
                        {else/}
                        <a href="javascript:;" id="loginclick">登录 | 注册</a>
                        {/if}
                    </li>

                    <li class="layui-nav-item"><a href="">菜单3</a></li>
                </ul>

            </div>
        </div>


    </div>

</div>
<!--头部导航结束。-->

<!--主体部分开始。-->
<div class="layui-fluid" style="padding-top: 10px">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md9">
            {block name="main"}{/block}
        </div>
        <div class="layui-col-md3">
            {include file="public/side"}
        </div>
    </div>
</div>

<!--主体部分结束。-->


<div style="display: none;" id="login">
    <div class="layui-tab" lay-filter="login-regist">
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="11">登 录</li>
            <li lay-id="22">注 册</li>
        </ul>

        <div class="layui-tab-content">

            <div class="layui-tab-item layui-show">
                <style>
                    .demo-login-container {
                        width: 320px;
                        margin: 21px auto 0;
                    }

                    .demo-login-other .layui-icon {
                        position: relative;
                        display: inline-block;
                        margin: 0 2px;
                        top: 2px;
                        font-size: 26px;
                    }
                </style>

                <form class="layui-form">
                    <div class="demo-login-container">
                        <div class="layui-form-item">
                            <div class="layui-input-wrap">
                                <div class="layui-input-prefix">
                                    <i class="layui-icon layui-icon-username"></i>
                                </div>
                                <input type="text" name="username" value="" lay-verify="required" placeholder="用户名"
                                       lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-wrap">
                                <div class="layui-input-prefix">
                                    <i class="layui-icon layui-icon-password"></i>
                                </div>
                                <input type="password" name="password" value="" lay-verify="required"
                                       placeholder="密   码" lay-reqtext="请填写密码" autocomplete="off" class="layui-input"
                                       lay-affix="eye">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-row">
                                <div class="layui-col-xs7">
                                    <div class="layui-input-wrap">
                                        <div class="layui-input-prefix">
                                            <i class="layui-icon layui-icon-vercode"></i>
                                        </div>
                                        <input type="text" name="captcha" value="" lay-verify="required" placeholder="验证码" lay-reqtext="请填写验证码" autocomplete="off" class="layui-input" lay-affix="clear">
                                    </div>
                                </div>
                                <div class="layui-col-xs5">
                                    <div style="margin-left: 10px;">
                                        <div><img src="{:captcha_src()}" alt="captcha" onclick="this.src=this.src+'?'+Math.random() " /></div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
                            <a href="#forget" style="float: right; margin-top: 7px;">忘记密码？</a>
                        </div>
                        <div class="layui-form-item">
                            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="sublogin">登录</button>
                        </div>
                        <div class="layui-form-item demo-login-other">
                             <a href="#reg" id="jump_login" >注册帐号</a>
                        </div>
                    </div>
                </form>
            </div>

            <div class="layui-tab-item">
                <style>
                    .demo-reg-container {
                        width: 320px;
                        margin: 21px auto 0;
                    }

                    .demo-reg-other .layui-icon {
                        position: relative;
                        display: inline-block;
                        margin: 0 2px;
                        top: 2px;
                        font-size: 26px;
                    }
                </style>
                <form class="layui-form">
                    <div class="demo-reg-container">
                        <div class="layui-form-item">
                            <div class="layui-row">
                                <div class="layui-col-xs7">
                                    <div class="layui-input-wrap">
                                        <div class="layui-input-prefix">
                                            <i class="layui-icon layui-icon-cellphone"></i>
                                        </div>
                                        <input type="text" name="username" value="" lay-verify="required|phone|usernamediy"
                                               placeholder="手机号" lay-reqtext="请填写手机号" autocomplete="off"
                                               class="layui-input" id="reg-cellphone">
                                    </div>
                                </div>
<!--                                <div class="layui-col-xs5">-->
<!--                                    <div style="margin-left: 11px;">-->
<!--                                        <button type="button" class="layui-btn layui-btn-fluid layui-btn-primary"-->
<!--                                                lay-on="reg-get-vercode">获取验证码-->
<!--                                        </button>-->
<!--                                    </div>-->
<!--                                </div>-->
                            </div>
                        </div>
<!--                        <div class="layui-form-item">-->
<!--                            <div class="layui-input-wrap">-->
<!--                                <div class="layui-input-prefix">-->
<!--                                    <i class="layui-icon layui-icon-vercode"></i>-->
<!--                                </div>-->
<!--                                <input type="text" name="vercode" value="" lay-verify="required" placeholder="验证码"-->
<!--                                       lay-reqtext="请填写验证码" autocomplete="off" class="layui-input">-->
<!--                            </div>-->
<!--                        </div>-->
                        <div class="layui-form-item">
                            <div class="layui-input-wrap">
                                <div class="layui-input-prefix">
                                    <i class="layui-icon layui-icon-password"></i>
                                </div>
                                <input type="password" name="password" value="" lay-verify="required|passworddiy" placeholder="密码"
                                       autocomplete="off" class="layui-input" id="reg-password" lay-affix="eye">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-wrap">
                                <div class="layui-input-prefix">
                                    <i class="layui-icon layui-icon-password"></i>
                                </div>
                                <input type="password" name="confirmPassword" value=""
                                       lay-verify="required|confirmPassword" placeholder="确认密码" autocomplete="off"
                                       class="layui-input" lay-affix="eye">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-wrap">
                                <div class="layui-input-prefix">
                                    <i class="layui-icon layui-icon-username"></i>
                                </div>
                                <input type="text" name="nickname" value="" lay-verify="required" placeholder="昵称"
                                       autocomplete="off" class="layui-input" lay-affix="clear">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <input type="checkbox" name="agreement" lay-verify="required" lay-skin="primary" title="同意">
                            <a href="#terms" target="_blank" style="position: relative; top: 6px; left: -15px;">
                                <ins>用户协议</ins>
                            </a>
                        </div>
                        <div class="layui-form-item">
                            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="sub-reg">注册</button>
                        </div>
                        <div class="layui-form-item demo-reg-other">
                            <a href="#login">登录已有帐号</a>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>

</div>

<!-- HTML Content -->
<script src="//cdn.staticfile.net/layui/2.9.14/layui.js"></script>
<script type="text/javascript">



    layui.use(['element', 'layer','form'], function () {
            var element = layui.element;
            var layer = layui.layer;
            var $ = layui.$
        var form = layui.form;

        // 如果不添加了下面这个验证规则，那么如果两次输入的密码不一样，也可以提交成功，加上了这个代码，就会在提交时，进入到这里，进行验证，就算这段代码放到了注册提交事件的后面，也会先执行这段代码。
        form.verify({
            // 验证用户名，且为必填项
            //这里为什么能执行？是因为这个在lay-verify="required|phone|usernamediy"里有usernamediy，这样设置的
            usernamediy: function(value, elem){
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '用户名不能有特殊字符';
                }
                if (/(^_)|(__)|(_+$)/.test(value)) {
                    return '用户名首尾不能出现下划线';
                }
                // if (/^\d+$/.test(value)) {
                //     return '用户名不能全为数字';
                // }
            },
            // 验证密码，且为必填项
            password: function(value, elem) {
                if (!/^[\S]{6,16}$/.test(value)) {
                    return '密码必须为 6 到 16 位的非空字符';
                }
            },
            // 确认密码
            confirmPassword: function(value, item){
                var passwordValue = $('#reg-password').val();
                if(value !== passwordValue){
                    return '两次密码输入不一致223';
                }
            }
        });


        // 提交事件
        form.on('submit(sublogin)', function(data){
            var field = data.field; // 获取表单字段值
            // 显示填写结果，仅作演示用
            layer.alert(JSON.stringify(field), {
                title: '当前填写的字段值'
            });
            // 此处可执行 Ajax 等操作
            // …
            return false; // 阻止默认 form 跳转
        });
        // 提交事件，这个是怎么找到这个提交事件的呢？用的是lay-filter=sub-reg,的lay-filter来定义的类似一个id的意思，然后用的submit()来包裹，
        form.on('submit(sub-reg)', function(data){
            $.ajax({
                type:"post",
                url:"{:url('login/register')}",
                data:data.field
            })
            var field = data.field; // 获取表单字段值
            // 显示填写结果，仅作演示用
            layer.alert(JSON.stringify(field), {
                title: '当前填写的字段值'
            });
            // 此处可执行 Ajax 等操作
            // …
            return false; // 阻止默认 form 跳转
        });

        layer.open({
            type: 1, // page 层类型
            area: ['500px', '600px'],
            title: '登录 注册',
            shade: 0.6, // 遮罩透明度
            shadeClose: true, // 点击遮罩区域，关闭弹层
            maxmin: true, // 允许全屏最小化
            anim: 0, // 0-6 的动画形式，-1 不开启
            content: $('#login')
        })
            $("#loginclick").click(function () {
                layer.open({
                    type: 1, // page 层类型
                    area: ['500px', '600px'],
                    title: '登录 注册',
                    shade: 0.6, // 遮罩透明度
                    shadeClose: true, // 点击遮罩区域，关闭弹层
                    maxmin: true, // 允许全屏最小化
                    anim: 0, // 0-6 的动画形式，-1 不开启
                    content: $('#login')
                })
            })

        $("#jump_login").click(function () {
            console.log("进来了切换tab")
                // 切换到指定 tab 项
                element.tabChange('login-regist', '22'); // 切换到：标签3

        })



        }
    )
</script>

{block name="js"}
{/block}
</body>
</html>